﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace WorldOnFire
{
    public class CDetonator : ABCEnemy
    {
        public float m_fSpinTimer;

        public override void Initialize(int _nObjectCount)
        {
            // Initialize base members
            base.Initialize(_nObjectCount);

            // Initialize the members
            m_fOrbitAngleLock = 0.2f;

            for (int iObject = 0; iObject < _nObjectCount; ++iObject)
            {
                m_fMass = 100.0f;
                m_fEngineForce = 10.0f * m_fMass;
                m_fMaximumSpeed = 15.0f;
                m_fTurnSpeed = 0.1f * (float)Math.PI;

                m_fMinimumRange = 0.0f;
                m_fMaximumRange = 0.0f;
                m_fShotDelayPrimary = 0.0f;
                m_fShotDelaySecondary = 0.0f;
                m_fShotSpeed = 0.0f;
                m_fDamage = 100.0f;
                m_fAreaOfEffect = 0.0f;
                m_fMaximumHealth = 100.0f;

                // TODO: SET TARGET INDEX
                m_nTargetIndex[iObject] = 0;
                m_fDisabledTimer[iObject] = 0.0f;
                m_fShotTimerPrimary[iObject] = 0.0f;

                // TODO: LOLWUT
                this.SetAIState(iObject, eAIState.CLOSING);
            }

            // Assign collidable types
            m_CollidableTypeList.Add(eObjectType.HOMEWORLD);
        }

        public override void LoadContent()
        {
            m_eModelID = CRenderingManager.eModelID.ENEMY_DETONATOR;

            base.LoadContent();
        }

        public override void Update(float _fDeltaTime)
        {
            // Update base members
            base.Update(_fDeltaTime);

            // TODO: A BARREL ROLL
            m_fSpinTimer += _fDeltaTime;
        }

        public override bool RespondToCollision(int _nIndex, ABCObject _Object, int _nObjectIndex)
        {
            // TODO: If it's the target, explode
            this.ScheduleForDeactivation(_nIndex);
            return false;
        }

        protected override void FirePrimary(int _nIndex)
        {
            // TODO: Blow up
            //s_ObjectManager.GetProjectile(ABCProjectile.eProjectileType.BOMB).CreateProjectile(this, _nIndex);
        }

        protected override void CopyRenderingTransforms()
        {
            // Loop through each index for rendering
            for (int iRenderingIndex = 0; iRenderingIndex < m_nObjectsActive; ++iRenderingIndex)
            {
                int nIndex = m_ActiveIndexList[iRenderingIndex];

                // Copy the transform into the rendering transform array
                m_mRenderingTransforms[iRenderingIndex] = m_mTransform[nIndex];

                // Rotate the transform
                Matrix mRotation = Matrix.CreateFromAxisAngle(
                    m_mRenderingTransforms[iRenderingIndex].Backward, 
                    m_fSpinTimer * 0.5f * (float)Math.PI);
                m_mRenderingTransforms[iRenderingIndex].Translation = Vector3.Zero;
                m_mRenderingTransforms[iRenderingIndex] = m_mRenderingTransforms[iRenderingIndex] * mRotation;
                m_mRenderingTransforms[iRenderingIndex].Translation = m_mTransform[nIndex].Translation;
            }
        }
    }
}
